<template>
  <div>
    <div style="display: flex;">
        <el-input v-model="file.name" placeholder="文件名" readonly clearable></el-input>
    <el-upload action="#" :show-file-list="false" :before-upload="beforeUpload">
      <el-button type="danger" >上传文件</el-button>
    </el-upload>
    <el-button icon="el-icon-download" type="primary" @click="handleExport">下载模板</el-button>
   
    </div>
    <div style="display: flex; width: 400px;">
      <el-input v-model="oaNumber" placeholder="工号"></el-input>
    <el-button icon="el-icon-download" type="primary" @click="handleInput">登录</el-button>

    </div>
    <render-table
      :border="true"
      :tableColumn="tableColumn"
      :apiUrl="listPurchase"
    >
    <template #opration='{row}'>
      <el-button @click="edit(row)">编辑</el-button>
      <el-button>查看</el-button>
      <el-button>删除</el-button>
    </template>
  </render-table>
  </div>
</template>

<script>
//具体接口名称在下方文件改
import { upload } from "@/api/supplier/api";
import { getOaCode } from "@/api/demo/api";
  import { listPurchase, getPurchase, delPurchase, addPurchase, updatePurchase } from "@/api/purchase/api";
export default {
    data(){
        return{
          oaNumber:'',
          listPurchase,
          tableColumn: [
        {
          label: "序号",
          type: "index",
          width: 50,
          align: "center",
        },
        {
          label: "学生",
          prop: "student",
          align: "center",
        },
        {
          label: "数学",
          align: "center",
          prop: "math",
        },
        {
          label: "语文",
          align: "center",
          prop: "language",
        },
        {
          label: "英语",
          prop: "english",
          align: "center",
          width: "200px"
        },
        {
          label:'操作',
          align:'center',
          width: 300,
          scopedSlots:{
            slots:true
          }
        }
      ],
      tableData: [
        {
          student: "张三",
          math: 60,
          language: 60,
          english: 60,
        },
        {
          student: "王五",
          math: 66,
          language: 80,
          english: 77,
        },
      ],
            file:{
                name:''
            },
            queryParams:{

            }
        }
    },
    methods:{
      handleInput(){
        getOaCode({oaNumber:this.oaNumber}).then((res)=>{
          console.log('res',res)
        })
      },
      
        // 上传预处理
    beforeUpload(file) {
        if (!/\.(xlsx|xls|XLSX|XLS)$/.test(file.name)) {
        this.$notify.error({
          title: "错误",
          message: "上传文件只能为excel文件，且为xlsx,xls格式",
        });
        }else{
            this.file.name = file.name
            let formData = new FormData
            formData.append('file',file)
            upload(formData).then((res) => {
                
            }).catch((err) => {
                
            });
        }
    },
    //下载模板
    handleExport() {
        this.download('system/purchase/export', {
          ...this.queryParams
        }, `purchase_${new Date().getTime()}.xlsx`)
      }
    }
}
</script>

<style>

</style>